package com.hyl.types.design.framework.tree;

import lombok.Getter;
import lombok.Setter;

/**
 * @author hyl
 * @description
 * @create 2025-06-15 17:39
 */
public abstract class AbstractMultiThreadStrategyRoute<T,D,R> implements StrategyHandler<T,D,R>, StrategyMapper<T,D,R> {

    @Getter
    @Setter
    protected StrategyHandler<T,D,R> defaultstrategyHandler = StrategyHandler.DEFAULT;
    public R router(T requestParameter,D dynamicContext) throws Exception{
        StrategyHandler<T, D, R> strategyHandler = get(requestParameter, dynamicContext);
        if (null != strategyHandler) return strategyHandler.apply(requestParameter, dynamicContext);
        return defaultstrategyHandler.apply(requestParameter, dynamicContext);
    }

    @Override
    public R apply(T requestParameter, D dynamicContext) throws Exception {
       mutiThread(requestParameter, dynamicContext);
       return doApply(requestParameter, dynamicContext);
    }
    protected abstract void mutiThread(T requestParameter, D dynamicContext) throws Exception;

    protected abstract R doApply(T requestParameter, D dynamicContext)throws Exception;


}
